Album: Mobile Album Information
The album
module provides multiple interfaces for applications to access system album.
Developers can determine whether these interfaces work in the EdgerOS mobile App environment through the following code:
edger.env().then(data => {
if (data.env === 'edgerapp') {
// We work in EdgerOS mobile App environment.
}
}).catch(error => {
console.error(error);
});
Functions
edger.album.query()
Query all albums to obtain detailed information for each individual album.
- Returns: {Promise} Fulfill upon success with an array object.
The returned query results can contain the following members:
albums
{Array} An array containing album objects, each of which includes the following members:count
{Number}: Number of items.name
{String}: Name of the album.path
{String}: Path of the album.type
{String}: Type of the album.url
{String}: URL of the album.
Album type
may include the following types:
Type | Description |
---|---|
'all' | All albums |
'sub' | A single album |
Example
edger.album.query().then((payload) => {
payload.albums.forEach((album) => {
const { type, name, path, url, count } = album;
console.log("albums info:", type, name, path, url, count);
})
}).catch(error => {
console.error(error);
});
async / await
async function albumQuery() {
try {
const payload = await edger.album.query();
payload.albums.forEach((album) => {
const { type, name, path, url, count } = album;
console.log("albums info:", type, name, path, url, count);
})
} catch (error) {
console.error(error);
}
}
edger.album.dir(params)
Query media file information within a specific album directory.
params
{Object} Parameters for the album directory.- Returns: {Promise} Fulfill upon success with an object.
The params
is an object, it can contain the following members:
name
{String}: The name of the album.order
{String}: Sorting order for the album. Optional values:desc
|asc
. Optional.limit
{Number}: The current page size of the album directory query. The default value is-1
, indicating retrieval of all entries. Optional.index
{Number}: The current page number for the album directory query. Optional.condition
{Object}: Additional conditions for the album directory query. Optional. It can contain the following members:beginAt
{Number}: The start time for the album directory query. Optional.endAt
{Number}: The end time for the album directory query. Optional.type
{String}: The type of the album.
Album type
may include the following types:
Type | Description |
---|---|
'all' | All albums |
'sub' | A single album |
The returned object can contain the following members:
count
{Number} Count.items
{Array} Array ofmediaFile
.
The items
in the returned object is an array of mediaFile
, each of which may contain the following members:
id
{String} File ID.name
{String} File Name.path
{String} File path.size
{String} File size.type
{String} File Type. Optional values:video
|livephoto
|livephoto#mov
|picture
|file
|directory
.mtime
{Number} Modification timestamp of the file (millisecond from 1970-01-01 00:00:00 UTC).birthtime
{Number} Creation timestamp of the file (millisecond from 1970-01-01 00:00:00 UTC).media
{Object} Media object.
The media
in mediaFile
is an object, it can contain the following members:
url
{String} Media URL.mov
{Object} IOS livephoto object. Optional.thumbnail
{Object} Thumbnail object.detail
{Object} More details.
The mov
in media
is an object, it can contain the following members:
type
{String} Livephoto type. Optional values:livephoto
|livephoto#mov
size
{Number} Livephoto size.path
{String} Livephoto path.url
{String} Livephoto url.
The thumbnail
in media
is an object, it can contain the following members:
type
{String} Thumbnail type. Optional values:picture
.size
{Number} Thumbnail size. Optional.path
{String} Thumbnail path.url
{String} Thumbnail url.
The detail
in media
is an object, it can contain the following members:
latitude
{Number} Latitude of file generation. Optional.longitude
{Number} Longitude of file generation. Optional.altitude
{Number} Altitude of file generation. Optional.width
{Number} Width of the image or video.height
{Number} Height of the image or video.duration
{Number} Playback duration. Optional.
Example
const params = {
name: 'Camera',
order: 'desc',
limit: 100,
index: 0
};
edger.album.dir(params).then((payload) => {
const { count, items } = payload;
console.log("album count:", count);
items.forEach((item) => {
const { id, name, size, type, path, birthtime, mtime, media } = item;
console.log("album dir info:", id, name, size, type, path, birthtime, mtime, media);
})
}).catch(error => {
console.error(error);
});
async / await
async function albumDir() {
try {
const payload = await edger.album.dir(params);
const { count, items } = payload;
console.log("album count:", count);
items.forEach((item) => {
const { id, name, size, type, path, birthtime, mtime, media } = item;
console.log("album dir info:", id, name, size, type, path, birthtime, mtime, media);
})
} catch (error) {
console.error(error);
}
}
edger.album.save(params, headers)
Save images or video media files to the system's file storage.
params
{Object} Basic request parameters.headers
{Object} Custom request header parameters. Default:{}
.- Returns: {Promise} Fulfill upon success with an object.
The params
is an object, it can contain the following members:
url
{String} Source download path.type
{String} File type. Optional values:picture
|video
.fileExt
{String} Extension. When thetype
ispicture
, the default isjpg
; When thetype
isvideo
, the default ismp4
. Optional.saveSystem
{Boolean} Iftrue
, save to the system directory, the path is usuallyPicture/
. Iffalse
, save to theEOS/
directory. Default:true
. It only takes effect in Android. Optional.
Get an object of result, the object includes:
id
{String} File ID.
Example
const params = {
url: 'https://img6.bdstatic.com/img/image/pcindex/sunjunpchuazhoutu.jpg',
type: 'picture'
};
const headers = {};
edger.album.save(params, headers).then((payload) => {
console.log('album save success', payload.id);
}).catch(error => {
console.error(error);
});
async / await
async function albumSave() {
try {
const payload = await edger.album.save(params, headers);
console.log('album save success', payload.id);
} catch (error) {
console.error(error);
}
}
Events
The unified event listener provided by Web-SDK:
const listener = (payload) => {
// Event handling...
}
// add listener
edger.album.addEventListener('some-event', listener);
// or
// onAction() is an alias of addEventListener().
edger.album.onAction('some-event', listener);
// remove listener
edger.album.removeEventListener('some-event', listener);
// remove all listeners
edger.album.removeAllListeners();
change
Triggered when the album content changes.
- Returns: {Object} This
mediaFile
object. ThemediaFile
object has astatus
attribute, it indicates the status of the current album.
Example
const listener = (payload) => {
payload.items.forEach((item) => {
const { status, name, size, type, birthtime, mtime, media } = item;
console.log("album change dir info:", status, name, size, type, birthtime, mtime, media);
})
}
edger.album.addEventListener('change', listener);